<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ include file="/pages/inc/taglibs.jsp" %>
<%@ page import="com.csi.jf.crucible.common.config.JfConstants" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>专家服务列表</title>
	<%@ include file="/pages/inc/header.jsp" %>
	<link rel="stylesheet" type="text/css" href="<c:url value='/styles/ptService/ptService.${webConfig["csssuffix"]}'/>" media="screen, projection"/>
	<style>
	#ptsprofessor{color:blue}
	</style>
</head>
<body>
<%@ include file="/pages/inc/common.jsp" %>
<%@ include file="/pages/inc/menu.jsp" %>

<div class="pts-main">
	<%@ include file="/pages/inc/nav_pm.jsp" %>
	<div class="pts-page-title"><span>服务目录</span></div>
	<div class="container-fluid">
		<input type="hidden" name="check" value="<%=JfConstants.PTS_SERVICE_CHECK %>"/>
		<input type="hidden" name="checking" value="<%=JfConstants.PTS_SERVICE_CHECHING %>"/>
		<input type="hidden" name="doing" value="<%=JfConstants.PTS_SERVICE_DOING %>"/>
		<input type="hidden" name="done" value="<%=JfConstants.PTS_SERVICE_DONE %>"/>
		<div id="proshow" class="pts-list"></div>  
		<div>
		  <div class="pts_icon_span">
			  <span id="pts_java_icon" class="pts-service-icon" onclick="chooseService(1)"></span>
			  <span>Java代码检查专家服务</span>
		  </div>
		  <div class="pts_icon_span">
			  <span id="pts_net_icon" class="pts-service-icon" onclick="chooseService(2)"></span>
			  <span>.Net代码检查专家服务</span>
		  </div>
		</div>
	</div>
	<div class="pts-page-title"><span>服务订单</span></div>
	<div class="container-fluid">
		<div class="ui-table ui-margin">
			<div class="nav">
				<!-- <button id="addBtn" class="button" type="button" onclick="add();">增加</button>
				<button id="editBtn" class="button" type="button" onclick="edit();">编辑</button>-->
				<button id="viewBtn" class="button" type="button" onclick="view();">查看</button>
				<button id="deleteBtn" class="button" type="button" onclick="batchDelete();">删除</button>
			</div> 
			<table id="serviceOrdersTable"></table>
			<div id="serviceOrdersPager"></div>
		</div>
	</div>
	<div id="editDialog" class="container-fluid" style="display:none">
		<form id="serviceOrdersFormEdit"  class="bizform">
			<div class="ui-table">
				<input type="hidden" id="edit_id" name="id" value="<c:out value='${serviceOrders.id}'/>"/>
				<table class="table">
					<tr>
						<td class="inputLabelTd">服务编号：</td>
						<td class="inputTd">
							<input id="edit_serviceID" name="serviceID" type="text" class="text"/>
						</td>
						<td class="inputLabelTd">服务名称：</td>
						<td class="inputTd">
							<input id="edit_serviceName" name="serviceName" type="text" class="text"/>
						</td>
					</tr>
					<tr>
						<td class="inputLabelTd">申请日期：</td>
						<td class="inputTd">
							<input id="edit_applyDate" name="applyDate" type="text" class="text"/>
						</td>
						<td class="inputLabelTd">专家编号：</td>
						<td class="inputTd">
							<input id="edit_professorID" name="professorID" type="text" class="text"/>
						</td>
					</tr>
					<tr>
						<td class="inputLabelTd">专家名称：</td>
						<td class="inputTd">
							<input id="edit_professorName" name="professorName" type="text" class="text"/>
						</td>
						<td class="inputLabelTd">开始执行时间：</td>
						<td class="inputTd">
							<input id="edit_exeBeginDate" name="exeBeginDate" type="text" class="text"/>
						</td>
					</tr>
					<tr>
						<td class="inputLabelTd">执行时间：</td>
						<td class="inputTd">
							<input id="edit_exedate" name="edit_exedate" type="text" class="text"/>
						</td>
					</tr>
					<tr>
						<td class="inputLabelTd">截止执行时间：</td>
						<td class="inputTd">
							<input id="edit_exeEndDate" name="exeEndDate" type="text" class="text"/>
						</td>
						<td class="inputLabelTd">服务价格：</td>
						<td class="inputTd">
							<input id="edit_servicePrice" name="servicePrice" type="text" class="text"/>
						</td>
					</tr>
					<tr>
						<td class="inputLabelTd">状态：</td>
						<td class="inputTd" colspan="3">
							<input id="edit_status" name="status" type="text" class="text"/>
						</td>
					</tr>
						<tr>
						<td class="inputLabelTd"></td>
						<td class="inputTd">
							<input id="operate" name="operate" type="text" class="text"/>
						</td>
					</tr>
				</table>
			</div>
		</form>
	</div>
	<div id="showDialog"></div>
	<div id="errorDialog"></div>
</div>

<%@ include file="/pages/inc/footer.jsp" %>
<script type="text/javascript">
	var check = $("[name='check']").val();
	var checking = $("[name='checking']").val();
	var doing = $("[name='doing']").val();
	var done = $("[name='done']").val();
	var serviceOrdersGrid;
	//处理申请时间数据
   function editStr(cellvalue, options, rowObject) {
	  if(cellvalue!=null){
        return cellvalue.replace(" 00:00:00","");
	  }
	  else
	    return "";
   }
	//处理状态信息
   function editStatus(cellvalue, options, rowObject) {
	   if(cellvalue == check){
       return "待审批";
	   }else if(cellvalue == checking){
		   return "审批中";
           }else if(cellvalue == doing){
               return "进行中";
               }else{
                return "已完成";
                   }		       
   }
   function editOperate(cellvalue, options, rowObject) {
	   var html ="";
	   html +="<a>查看意见</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a>查看报告</a>"
	   if(rowObject.status == done){
       return html;
	   }else{
           return "";
		   }		       
   }
   //计算执行时间
   function editDate(cellvalue, options, rowObject) {
	   var date="";
	   if(cellvalue!=null){
	      var exeBeginDate = rowObject.exeBeginDate.replace(" 00:00:00","");
	      var exeEndDate = rowObject.exeEndDate.replace(" 00:00:00","");
          date = exeBeginDate+"至"+exeEndDate;
	   }
	   return date;
   }
    $(function(){
    	serviceOrdersGrid = new biz.grid({
    		id : "#serviceOrdersTable",
    		url : "serviceOrders/listServiceOrders",
			rowNum : 15,
			width:"auto",
			multiselect:true,
    		pager : "#serviceOrdersPager",
    		prmNames : {page:"pageNo",rows:"pageSize",sort:"orderFields",order:"order"},
    		sortname : "",
    		sortorder : "",
    		colModel : [
    			{name : "id", hidden:true,key:true}, 
/* 				{name : "id",formatter:"showlink",formatoptions:{baseLinkUrl:"#",click:view},label:"id"},
				{name : "serviceID",label:"服务编号"}, */
				{name : "serviceName",label:"服务名称"},
				{name : "applyDate",label:"申请日期",formatter:editStr},
				{name : "professorID",label:"专家编号"},
				{name : "professorName",label:"专家名称"},
				{name : "edit_exedate",label:"执行时间",formatter:editDate},
				{name : "servicePrice",label:"服务价格"},
				{name : "status",label:"状态",formatter:editStatus},
				{name : "operate",label:"操作",formatter:editOperate}
    		],
    		serializeGridData:function(postData){//添加查询条件值
				var obj = biz.utils.serializeObject("#serviceOrdersForm");//示例中心搜索"biz.utils方法详解"查看方法说明
    			$.extend(true,obj,postData);//合并查询条件值与grid的默认传递参数
    			return obj;
    		}
    	});
    })
    
	function query(){
		serviceOrdersGrid.setGridParam({"page":"1"});
		serviceOrdersGrid.trigger('reloadGrid');
	}

	var isEdit = true;//true:当前对话框为编辑操作  false：当前对话框为新增操作
	var editDialog = new biz.dialog({
		id:"#editDialog",
		autoOpen:false,
		title:"专家服务  录入",
		width:"80%",
		modal:true,
		buttons: [
			{
				text: I18N.save,
				click: function() {
					if(isEdit){
						update();
					}else{
						save(); 
					}
				}
			 },
			{text: I18N.cancel,click: function() { editDialog.close();}}
		]
	});
	var showDialog;
	var showDialogOption = {
		id:"#showDialog",
		autoOpen:false,
		title:"专家服务  详细",
		width:"80%",
		modal:true,
		buttons: [
			{
				text: I18N.close,
				click: function() { 
					showDialog.close();
					showDialog.destroy();
				}
			}
		]
	};
	function add(){
		isEdit = false;
		biz.utils.resetForm("#serviceOrdersFormEdit");
		editDialog.open();
	}

	function save(){
		if(!biz.validate("valid","#serviceOrdersFormEdit")){
			showWarn("<fmt:message key='validation.object'/>",3000);
			return;
		}
		new biz.ajaxsubmit({
        	id:"#serviceOrdersFormEdit",
       		method:"POST",
       		dataType:"json",
        	url: "<c:url value='/serviceOrders/save'/>",
        	success: function(data, textStatus, jqXHR){
				editDialog.close();
				query();
				showInfo("<fmt:message key='add.success'/>",3000);
			},
			error:biz.utils.loadError
   		});
	}
	
	function edit(rowid){
		isEdit = true;
		biz.utils.clearForm("#serviceOrdersFormEdit");
		rowid = serviceOrdersGrid.getGridParam("selarrrow");
		if(rowid == null || rowid.length == 0){
			showInfo("<fmt:message key='grid.edit.chooseColAlert'/>",3000);
			return ;
		}else if(rowid.length > 1){
			showInfo("<fmt:message key='grid.edit.onlyOne'/>",3000);
			return ;
		}
		var id = serviceOrdersGrid.getCell(rowid,"id");
		var dataUrl = "serviceOrders/edit/" + id;
		
		$.ajax({
			url: dataUrl,
			dataType:"json",
			cache:false,
			success: function(data, textStatus, jqXHR){
				biz.utils.val("edit_serviceID",data["serviceID"]);
				biz.utils.val("edit_serviceName",data["serviceName"]);
				biz.utils.val("edit_applyDate",data["applyDate"]);
				biz.utils.val("edit_professorID",data["professorID"]);
				biz.utils.val("edit_professorName",data["professorName"]);
				biz.utils.val("edit_exeBeginDate",data["exeBeginDate"]);
				biz.utils.val("edit_exeEndDate",data["exeEndDate"]);
				biz.utils.val("edit_servicePrice",data["servicePrice"]);
				biz.utils.val("edit_status",data["status"]);
				biz.utils.val("edit_id",data["id"]);
				editDialog.open();
			},
			error:biz.utils.loadError
		});	
	}
	
	function update(){
		if(!biz.validate("valid","#serviceOrdersFormEdit")){
			showWarn("<fmt:message key='validation.object'/>",3000);
			return;
		}
		rowid = serviceOrdersGrid.getGridParam("selrow");
		new biz.ajaxsubmit({
			id:"#serviceOrdersFormEdit",
			method:"POST",
			dataType:"json",
			url: "<c:url value='/serviceOrders/update'/>",
			success: function(data, textStatus, jqXHR){
				rowid = serviceOrdersGrid.getGridParam("selrow");
				serviceOrdersGrid.setRowData(rowid,data);
				editDialog.close();
				showInfo("<fmt:message key='add.success'/>",3000);
			},
			error:biz.utils.loadError
		});
	}
	function view(rowid){
		if(rowid == null){
			var rows = serviceOrdersGrid.getGridParam("selarrrow");
    		if(rows == null || rows.length == 0){
    			showInfo("<fmt:message key='grid.view.chooseColAlert'/>",3000);
    			return ;
    		}else if(rows.length > 1){
    			showInfo("<fmt:message key='grid.view.onlyOne'/>",3000);
    			return ;
    		}
			rowid = rows[0];
		}
		var id = serviceOrdersGrid.getCell(rowid,'id');
		var dataUrl = "serviceOrders/show?id=" + id;
		$.ajax({
			url: dataUrl,
			cache:false,
			success: function(data, textStatus, jqXHR){
				showDialog = new biz.dialog(showDialogOption);
				$(showDialog.id).html(data)
				showDialog.open();
			},
			error:biz.utils.loadError
		});
	}
	function batchDelete(rowid){
		var rowid = serviceOrdersGrid.getGridParam('selarrrow');
		if(rowid == null || rowid.length == 0){
			showInfo("<fmt:message key='grid.delete.chooseColAlert'/>",3000);
			return ;
		}
		new biz.alert({type:"confirm",message:I18N.msg_del_confirm,
			title:I18N.promp,callback:function(result){
	    		if (!result) {
	    			return;
	    		}
	    		var ids="";
	    		for(var i=0; i < rowid.length;i++){
	    			var id = serviceOrdersGrid.getCell(rowid[i],"id");
	    			if(i>0){
	    				ids +=',';
	    			}
	    			ids += id;
	    		}
	    		var dataUrl = "serviceOrders/delete/" + ids;
				$.ajax({
					url: dataUrl,
					cache:false,
					success: function(data, textStatus, jqXHR){
						query();
						showInfo("<fmt:message key='delete.success'/>",3000);
					},
					error:biz.utils.loadError
				});
			}
		});
	}

	function chooseService(serviceID) {
		window.location.href="<c:url value='/serviceOrders/applyService' />?serviceID=" + serviceID;
	}


</script>
</body>
</html>